A good answer might be:

Not a good idea. This would prevent the system from crashing, but probably hides some other serious problem with the input data.

Complete Program

Here is a complete program that uses the factorial() method:

//FactorialTester.java
//
class FactorialCalc
{
  int fact( int N )
  {
    if ( N == 0 )
      return 1;
    else
      return N * fact( N-1 ) ;
  }
}

class FactorialTester
{
  public static void main ( String[] args)
  {
    int argument = 10;
    FactorialCalc f = new FactorialCalc();
    int result = f.fact( argument );
    System.out.println("Factorial(" + argument + ") is " + result );
  }
}

Here is a run of the program:

C:\JavaNotes\Recursion03>javac FactorialTester.java

C:\JavaNotes\Recursion03>java FactorialTester
Factorial(10) is 3628800

QUESTION 6:

Here is another run of the program with a new value for the argument:

C:\JavaNotes\Recursion03>java FactorialTester
Factorial(17) is -288522240

That answer does not look correct. What went wrong?